#include<stdio.h>
#include<iostream>
using namespace std;
#define max 30
int R[3][max],  co[ max], up[max], down[max], s[max];
int k, n;
void Dfs(int depth, int row, int col)
{
    int i, j ;
    s[depth++] = col + 1;
    if (depth == n)
    {
        if (k < 3)
        {
            for (i = 0; i < depth; i++)
            {
                R[k][i] = s[i];
            }
        }
        k++;
    }
    else
    {
        co[col] = 0;
        up[row + col] = 0;
        down[col + n - row - 1] = 0;
        i = row + 1;
        if (i < n)
        {
            for (j = 0; j < n; j++)
            {
                if (co[j] && up[i + j] && down[j + n - i - 1])
                {
                    Dfs(depth, i, j);
                }
            }
        }
        co[col] = 1;
        up[row + col] = 1;
    down[col + n - row - 1] = 1;
    }
    
};
int main()
{
   // FILE * fin = fopen("checker.in", "r");
    //FILE * fout = fopen("checker.out", "w");
    int i, j, m, sum;
    scanf( "%d", &n);
    for (i = 0; i < max; i++)
    {
        co[i] = 1;
        up[i] = 1;
        down[i] = 1;
    }
    k = 0;
    if (n > 6)
    {
        if (n % 2 == 0)
        {
            m = 0;
        }
        else
        {
            m = 1;
        }
        for (i = 0; i < n / 2; i++)
        {
            Dfs(0,     0, i);
        }
        sum = k;
        if (m)
        {
            Dfs(0, 0, n / 2);
        }
        for (i = 0; i < 3; i++)
        {
            for (j = 0; j < n - 1; j++)
            {
                printf("%d ", R[i][j]);
            }
            printf("%d\n", R[i][j]);
        }
        if (m)
        {
            printf("%d\n", sum * 2 + k - sum );
        }
        else
        {
            printf( "%d\n", sum * 2);
        }
    }
    else
    {
        for (i = 0; i < n; i++)
        {
            Dfs(0,     0, i);
        }
        for (i = 0; i < 3; i++)
        {
            for (j = 0; j < n - 1; j++)
            {
                printf("%d ", R[i][j]);
            }
            printf("%d\n", R[i][j]);
        }
        printf("%d\n", k);
    }
    system("pause");
    return 0;
}
